package com.ojoin.trade.common_core.web.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.ojoin.trade.common.exception.BusinessException;
import com.ojoin.trade.common.utils.LogUtils;
import com.ojoin.trade.common.web.dao.BaseDao;
import com.ojoin.trade.common.web.service.impl.BaseServiceImpl;
import com.ojoin.trade.common_core.web.dao.TbTransferTokenStatusDao;
import com.ojoin.trade.common_core.web.domain.TbTransferTokenStatus;
import com.ojoin.trade.common_core.web.domain.TransferErrorStatusInfo;
import com.ojoin.trade.common_core.web.service.TransferTokenStatusService;

/**
 * 转账操作状态记录服务实现
 * @author guoting
 *
 */
@Service
public class TransferTokenStatusServiceImpl extends BaseServiceImpl<TbTransferTokenStatus> implements
		TransferTokenStatusService {
	
	@Autowired
	private TbTransferTokenStatusDao dao;
	
	@Override
	protected BaseDao<TbTransferTokenStatus> getBaseDao() {
		return dao;
	}

	/**
	 * 新建转账操作记录，生成token并返回(T0000017)
	 */
	@Override
	public String insertTransferTokenInfo(TbTransferTokenStatus statusvo) throws BusinessException {
		LogUtils.getT0loanLog().info("新建转账操作记录，生成token并返回. statusvo->" + statusvo.toString());
		
		this.getBaseDao().insert(statusvo);
		return statusvo.getToken();
	}

	/**
	 * 更新转账操作状态(T0000018)
	 */
	@Override
	public int updateTransferTokenStatus(String token, int transstatus,String msg)
			throws BusinessException {
		LogUtils.getT0loanLog().info("更新转账操作状态. token->" + token + ", transstatus->" + transstatus);
		
		return ((TbTransferTokenStatusDao) this
				.getBaseDao()).updateTransferTokenStatus(token, transstatus,msg);
	}

	/**
	 * 查询转账状态异常列表(T0000032)
	 */
	@Override
	public List<TransferErrorStatusInfo> queryDoingTransferList(Pageable page)
			throws BusinessException {
		LogUtils.getT0loanLog().info("查询转账状态异常列表. pageno->" + page.getPageNumber() + ", pagesize->" + page.getPageSize());
		
		return ((TbTransferTokenStatusDao) this
				.getBaseDao()).queryDoingTransferList(page);
	}

    @Override
    public TransferErrorStatusInfo queryByToken(String token) throws BusinessException {
        return ((TbTransferTokenStatusDao) this
                .getBaseDao()).queryByToken(token);
    }

}
